package com.bll;

import java.util.ArrayList;

import com.dal.DefectStatusDAO;
import com.model.DefectStatus;

public class DefectStatusBLO {
	
	public enum DefectStatusEnum {
		Error(1),
		Assigned(2),
		Fixing(3),
		Corrected(4),
		Delivered(5),
		Validated(6),
		Approved(7),
		Closed(8),
		Confirmed(9),
		Cancelled(10);
		
		private final int id ;
		DefectStatusEnum(int i){
			id = i;
		}
		
		DefectStatusEnum parse(int i) throws Exception{
			  for (DefectStatusEnum e : DefectStatusEnum.values()) {
		            if (e.id == id) {
		                return e;
		            }
		        }
		        return null;
		}
	}
	/*
	 * Properties
	 */
	private int defectStatusId;
	private String defectStatusName;
	
	
	public DefectStatusBLO(int DefectStatusId, String DefectStatusName) {
		super();
		this.defectStatusId = DefectStatusId;
		this.defectStatusName = DefectStatusName;
	}


	// Methods
	
	public static ArrayList<DefectStatusBLO> loadAllDefectStatus(){
		ArrayList<DefectStatus> list = new DefectStatusDAO().select();
		return getDefectStatusBLOListFromEntityList(list);
	}
	
	// Internal Methods
	private static ArrayList<DefectStatusBLO> getDefectStatusBLOListFromEntityList(ArrayList<DefectStatus> list){
		ArrayList<DefectStatusBLO> DefectStatusBLOlist = new ArrayList<DefectStatusBLO>();
		for (DefectStatus DefectStatus : list) {
			DefectStatusBLOlist.add( getDefectStatusBLOFromEntity(DefectStatus) );
		}
		return DefectStatusBLOlist;
	}
	
	private static DefectStatusBLO getDefectStatusBLOFromEntity(DefectStatus entity){
		return new DefectStatusBLO( entity.getDefectStatusID(),
						entity.getDefectStatusName());
	}

	
	// Utility Methods
	public String getDisplayText(){
		return defectStatusName;
	}
	/**
	 * @return the DefectStatusId
	 */
	public int getDefectStatusId() {
		return defectStatusId;
	}

	/**
	 * @param DefectStatusId the DefectStatusId to set
	 */
	public void setDefectStatusId(int DefectStatusId) {
		this.defectStatusId = DefectStatusId;
	}

	/**
	 * @return the DefectStatusName
	 */
	public String getDefectStatusName() {
		return defectStatusName;
	}

	/**
	 * @param DefectStatusName the DefectStatusName to set
	 */
	public void setDefectStatusName(String DefectStatusName) {
		this.defectStatusName = DefectStatusName;
	}

}
